<?php
namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;

class Lastteacher extends Backend
{
    protected $model = null;
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\FormTeacher;

    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $sqlcnt = 'select count(1) cnt from (select max(id) id from qa_form_teacher group by jobno) t';
            $cnt = Db::query($sqlcnt);
            $total = $cnt[0]['cnt'];

            $sql = "select tmp.*, c.name cname, qc.name crname from 
                (select * from qa_form_teacher ft,
                (select max(id) tid from qa_form_teacher group by jobno limit $offset, $limit) t
                where ft.id = t.tid) tmp left join qa_college c on tmp.cid = c.id
                left join qa_classroom qc on tmp.crid = qc.id";
            $rows = Db::query($sql);
            $result = array("total" => $total, "rows" => $rows);

            return json($result);
        }
        return $this->view->fetch();
    }

}